open Castling;;

module PvToken = struct
	type t = [`x | `y | `z | `eof | `none | `error of string];;
	let eof = `eof;;
	let invalid = Some `none;;
	let compare: t -> t -> int = Pervasives.compare;;
	let pp ~(quali: bool) ~(paren: bool) (f: Format.formatter) (item: t): unit = (
		match item with
		| `x -> Format.fprintf f "`x"
		| `y -> Format.fprintf f "`y"
		| `z -> Format.fprintf f "`z"
		| `eof -> Format.fprintf f "`eof"
		| `none -> Format.fprintf f "`none"
		| `error s -> Format.fprintf f "`error \"%s\"" (String.escaped s)
	);;
	let pp_pattern = pp;;
	let pp_typename ~(quali: bool) ~(paren: bool) (f: Format.formatter) (items: t list): unit = (
		Format.fprintf f "[@[";
		let (_: bool) = (
			List.fold_left (fun first item ->
				if not first then Format.fprintf f "@ | ";
				pp ~quali:false ~paren:false f item;
				false
			) true items
		) in
		if List.mem `eof items then Format.fprintf f "@ | `error of string";
		Format.fprintf f "@]]"
	);;
end;;

module PvPG = ParserGenerator (PvToken);;
open PvPG;;

let rec test = lazy !! (
	one_of ~name:"s" [
		"a", element `x;
		"a", element `y;
		"b", element `x >> element `y] >>
	element `z
);;

debug := true;;
runtime_debug := true;;
pretty_printer := true;;
error_printer := true;;
polymorphic_variants := true;;
generate test;;
